home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5536 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: cs.utexas.edu!not-for-mail
  2. From: wilson@cs.utexas.edu (Paul Wilson)
  3. Newsgroups: comp.lang.lisp,comp.lang.c++
  4. Subject: Re: Why garbage collection?
  5. Date: 5 Feb 1996 09:14:46 -0600
  6. Organization: CS Dept, University of Texas at Austin
  7. Message-ID: <4f56t6$7i0@jive.cs.utexas.edu>
  8. References: <rvillDL4v3n.I8r@netcom.com> <822848307snz@wildcard.demon.co.uk> <4eu5l9$5m9@jive.cs.utexas.edu> <823365355snz@wildcard.demon.co.uk>
  9. NNTP-Posting-Host: jive.cs.utexas.edu
  10.  
  11. In article <823365355snz@wildcard.demon.co.uk>,
  12. Cyber Surfer  <cyber_surfer@wildcard.demon.co.uk> wrote:
  13. >In article <4eu5l9$5m9@jive.cs.utexas.edu>
  14. >           wilson@cs.utexas.edu "Paul Wilson" writes:
  15. >
  16. >Was I refering to modern GC? I'm not sure. I don't know of any books
  17. >on modern GC, but a book 20 years old seems to contain GC techniques
  18. >that many C/C++ programmers are unaware of. Even if that's the best
  19. >book on the subject, it could still enlighten a few programmers.
  20.  
  21. True.  Simple GC techniques are acceptable for a fair number of applications.
  22. My favorite example is scripting languages.  Most scripting languages are
  23. so slow that the cost of GC is negligible, even if it's implemented badly
  24. by the standards of the state of the art.  People often use reference counting
  25. because that's what the C++ books give examples of, when mark-sweep would
  26. work like a charm, and often when copying collection wouldn't be very
  27. hard.  Reference counting works well in the sense that it wastes little
  28. space most of the time---getting space back immediately in most cases,
  29. rather than waiting until the next GC---but for a slow language implementation,
  30. mark sweep is just about as efficient if you crank the GC frequency up.
  31.  
  32. With a simple non-generational GC, you may pay a fair amount of CPU time
  33. to get space back quickly, but for scripting languages that cost is still
  34. usually swamped by the cost of interpretation.  The real cost may be in
  35. locality, because a simple GC touches most or all of the live data at
  36. each GC cycle.  So you'd rather have a generational GC.
  37.  
  38. And a generational GC is pretty easy to implement, too.  Appel implemented
  39. a decent generational GC for ML in 500 lines of C code.  For fast implemen-
  40. tations of general-purposes languages, you may want something a little
  41. fancier (his write barrier is probably too simple), but not much fancier.
  42. For a scripting language, a 500 line GC is probably plenty fast.
  43.  
  44. -- 
  45. | Paul R. Wilson, Comp. Sci. Dept., U of Texas @ Austin (wilson@cs.utexas.edu)
  46. | Papers on memory allocators, garbage collection, memory hierarchies,
  47. | persistence and  Scheme interpreters and compilers available via ftp from 
  48. | ftp.cs.utexas.edu, in pub/garbage (or http://www.cs.utexas.edu/users/wilson/)      
  49.